import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/hall_of_fame/hall_of_fame_controller.dart';
import 'package:flutter_changdian_football/pages/mine/user_store.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/custom_constant.dart';
import 'package:flutter_changdian_football/utils/str_utils.dart';
import 'package:flutter_changdian_football/widget/extended_image_slide_widget.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

class HallOfFameItem extends StatelessWidget {
  const HallOfFameItem({
    super.key,
    this.index = 0,
  });

  final int index;


  @override
  Widget build(BuildContext context) {
    return GetBuilder<HallOfFameController>(
      builder: (hallOfFameController) {
        return GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () {
            if (UserStore.to.checkLoginPage()) {
              Get.toNamed(AppRoutes.playerInfo, parameters: {
                'type': CustomConstant.USER_JB_INFO,
                'queriedUserId': '${hallOfFameController.userRankList[index].userId ?? ''}'
              });
            }
          },
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.w),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12.r),
              color: Colors.white
            ),
            child: Row(
              children: [
                  Container(
                    width: 48.w,
                    height: 48.w,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(48.r),
                      color: const Color(0xffEDF5F1)
                    ),
                    padding: EdgeInsets.all(4.w),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(48.r),
                      child: Image.network(hallOfFameController.userRankList[index].imageUrl ?? '', fit: BoxFit.fill, excludeFromSemantics: true, gaplessPlayback: true,),
                    ),
                  ),
        
                SizedBox(width: 8.w,),
        
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(
                        child: Row(
                          children: [
                            Flexible(
                              child: Text(hallOfFameController.userRankList[index].nickname ?? '', style: TextStyle(fontSize: 15.sp, fontWeight: FontWeight.w500, color: const Color(0xff333333)), maxLines: 1, overflow: TextOverflow.ellipsis,),
                            ),
                            SizedBox(width: 8.w,),
                            SizedBox(
                              width: 16.w,
                              height: 16.w,
                              child: Image.asset(StrUtils.getSexImage(hallOfFameController.userRankList[index].sex ?? 0)),
                            )
                          ],
                        ),
                      ),
        
                      SizedBox(height: 4.w,),
        
                      SizedBox(
                        width: 69.w,
                        height: 18.w,
                        child: Image.asset(StrUtils.getLevelImage(hallOfFameController.userRankList[index].grade ?? 1)),
                      )
                    ],
                  ),
                ),
        
                SizedBox(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      SizedBox(
                        width: 22.w,
                        height: 22.w,
                        child: index < 3 ? Image.asset('assets/images/icon_no${index + 1}.png', fit: BoxFit.fill,) :
                          index > 9 ? Container() : Container(
                            decoration: BoxDecoration(
                              color: const Color(0xff499360),
                              borderRadius: BorderRadius.circular(22.r)
                            ),
                            alignment: Alignment.center,
                            child: Text('${index + 1}', style: TextStyle(fontSize: 12.sp, color: Colors.white),),
                          ),
                      ),
        
                      SizedBox(height: 4.w,),
        
                      Container(
                        constraints: BoxConstraints(
                          maxHeight: 18.w,
                          maxWidth: 140.w
                        ),
                        child: ListView.separated(
                          itemCount: hallOfFameController.userRankList[index].goodPosition?.length ?? 0,
                          shrinkWrap: true,
                          scrollDirection: Axis.horizontal,
                          separatorBuilder: (context, subIndex) {
                            return SizedBox(width: 4.w,);
                          },
                          itemBuilder: (BuildContext context, int subIndex) {
                            return Container(
                              decoration: BoxDecoration(
                                color: StrUtils.getColorByCode(hallOfFameController.userRankList[index].goodPosition?[subIndex].positionSortCode).withOpacity(0.1),
                                borderRadius: BorderRadius.circular(15.r)
                              ),
                              padding: EdgeInsets.symmetric(vertical: 2.w, horizontal: 9.w),
                              child:  Text(hallOfFameController.userRankList[index].goodPosition?[subIndex].subdivisionPosition ?? '', style: TextStyle(fontSize: 10.sp, color: 
                              StrUtils.getColorByCode(hallOfFameController.userRankList[index].goodPosition?[subIndex].positionSortCode))),
                            );
                          },
                        ),
                      )
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      }
    );
  }
}